import serial
import threading
import time
import json
from .base_vehicle_controller import BaseVehicleController
from .controller_registry import ControllerRegistry


class VehicleController:
    def __init__(self, controller_type="DifferentialDrive"):
        """初始化车辆控制器

        Args:
            controller_type (str): 控制器类型
        """
        controller_class = ControllerRegistry.get_controller(controller_type)
        self.controller = controller_class()
        print(f"使用控制器类型: {controller_type}")

    def send_command(self, msg):
        self.controller.send_command(msg)

    def get_sensor_data(self):
        return self.controller.get_sensor_data()

    def get_controller_type(self):
        return self.controller.controller_type

    def stop(self):
        self.controller.stop()
            
